import { MockMethod } from 'vite-plugin-mock'
import { ResultEnum, ResponseEnum } from '@/enums/HttpEnums'
import Mock from 'mockjs'
const Random = Mock.Random

const getList = (count, query: any) => {
  const list: any = []
  for (let index = 0; index < count; index++) {
    const element = {
      id: '@id',
      userName: '@cname',
      gender: query.gender || Random.integer(0, 1),
      age: Random.integer(18, 40),
      account: '@first',
      email: Random.email('163.com'),
      title: '@csentence(10, 15)',
      createTime: '@datetime',
      status: Random.integer(0, 1)
    }
    list.push(element)
  }
  return list
}

export default [
  {
    url: '/mock-api/auth/captcha',
    method: 'get',
    timeout: ResponseEnum.TIMEOUT,
    response: () => {
      return {
        code: ResultEnum.SUCCESS,
        data: Mock.mock({
          id: '@id',
          userName: '@cname',
          account: '@first',
          email: Random.email('163.com'),
          title: '@csentence(10, 15)',
          createTime: '@datetime',
          status: Random.natural(0, 1)
        }),
        msg: '操作成功'
      }
    }
  },
  {
    url: '/mock-api/test/getList',
    method: 'get',
    timeout: ResponseEnum.TIMEOUT,
    response: ({ query }) => {
      console.log('query', query)

      return {
        code: ResultEnum.SUCCESS,
        data: Mock.mock({
          list: getList(217, query),
          pageNum: parseInt(query.pageNum)
        }),
        msg: '操作成功'
      }
    }
  }
] as MockMethod[]
